﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string inputA = textBox1.Text;
            string inputB = textBox2.Text;
            double a, b;
            if (double.TryParse(inputA, out a) && double.TryParse(inputB, out b))
            {
                double result = 0;
                if (checkedListBox1.CheckedItems.Count > 0)
                {
                    string operation = checkedListBox1.CheckedItems[0].ToString();
                    switch (operation)
                    {
                        case "+":
                            result = a + b;
                            break;
                        case "-":
                            result = a - b;
                            break;
                        case "*":
                            result = a * b;
                            break;
                        case "/":
                            if (b != 0)
                            {
                                result = a / b;
                            }
                            else
                            {
                                MessageBox.Show("除数不能为零");
                                return;
                            }
                            break;
                        default:
                            MessageBox.Show("未选择运算符");
                            return;
                    }
                    textBox4.Text = result.ToString();
                }
            }
            else
            {
                MessageBox.Show("请输入数字");
            }
        }
    }
    }
